package com.student.Activitys.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.student.Activitys.R;

/**
 * 项目名称：智慧校园学生端
 * 类描述：日课表 dialog
 * 创建人：张飞祥
 * 创建时间：2017/9/27 16:17
 * 修改人：张飞祥
 * 修改时间：2017/9/27 16:17
 * 修改备注：
 */
public abstract class ScheduleDayDialog extends Dialog implements View.OnClickListener {

    //期末评价
    TextView dialogDayEvaluate;
    //课堂反馈
    TextView dialogDayFeedback;
    //请假
    TextView dialogDayLeave;
    //签到
    TextView dialogDaySign;


    private Activity activity;

    public ScheduleDayDialog(@NonNull Activity activity) {
        super(activity, R.style.MyDialogTheme);
        this.activity = activity;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        //初始化加载
        setContentView(R.layout.dialog_schedule_day);
        dialogDayEvaluate = (TextView) findViewById(R.id.dialog_day_evaluate);
        dialogDayFeedback = (TextView) findViewById(R.id.dialog_day_feedback);
        dialogDayLeave = (TextView) findViewById(R.id.dialog_day_leave);
        dialogDaySign = (TextView) findViewById(R.id.dialog_day_sign);

        //点击事件监听
        dialogDayEvaluate.setOnClickListener(this);
        dialogDayFeedback.setOnClickListener(this);
        dialogDayLeave.setOnClickListener(this);
        dialogDaySign.setOnClickListener(this);

        //设置dialog 样式
        setViewLocation();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.dialog_day_evaluate:
                evaluate();
                this.cancel();
                break;
            case R.id.dialog_day_feedback:
                feedback();
                this.cancel();
                break;
            case R.id.dialog_day_leave:
                leave();
                this.cancel();
                break;
            case R.id.dialog_day_sign:
                sign();
                this.cancel();
                break;
        }
    }

    public abstract void evaluate();      //评价
    public abstract void feedback();      //课堂反馈
    public abstract void leave();         //请假
    public abstract void sign();          //签到

    /**
     * 设置dialog位于屏幕底部
     */
    private void setViewLocation() {
        DisplayMetrics dm = new DisplayMetrics();
        activity.getWindowManager().getDefaultDisplay().getMetrics(dm);
        int height = dm.heightPixels;

        Window window = this.getWindow();
        WindowManager.LayoutParams lp = window.getAttributes();
        lp.x = 0;
        lp.y = height;
        lp.width = ViewGroup.LayoutParams.MATCH_PARENT;
        lp.height = ViewGroup.LayoutParams.WRAP_CONTENT;
        // 设置显示位置
        onWindowAttributesChanged(lp);
    }
}
